package com.meilai.project.controller.web.administration.goods;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.meilai.project.dto.CommonResult;
import com.meilai.project.service.administration.goods.GoodsStorageChangeRecordService;
import com.meilai.project.vo.administration.goods.GoodsOutStorageVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * <p>
 * 物品库存变化表 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-12-21
 */
@RestController
@RequestMapping("/api/web/goods_storage_change_record")
public class GoodsStorageChangeRecordController {

    @Autowired
    private GoodsStorageChangeRecordService service;


    @ApiOperation(value = "所有出库单列表", notes = "库管，查看所有出库记录", response = GoodsOutStorageVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"),
            @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"),
            @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"),
            @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"),
            @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("list")
    public CommonResult list(
            @ApiParam(name = "page", value = "当前页", required = true)
            @RequestParam(value = "page", defaultValue = "1", required = true) Integer page,
            @ApiParam(name = "page_size", value = "每页数量", required = true)
            @RequestParam(value = "page_size", defaultValue = "10", required = true) Integer page_size,
            @ApiParam(name = "goods_type_ids", value = "物品类型id")
            @RequestParam(value = "goods_type_id", required = false) Long goods_type_id,
            @ApiParam(name = "begin_date", value = "数量最小值")
            @RequestParam(value = "begin_date", required = false)
            @JsonFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin_date,
            @ApiParam(name = "end_date", value = "数量最小值")
            @RequestParam(value = "end_date", required = false)
            @JsonFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end_date,
            @ApiParam(name = "user_id", value = "用户id")
            @RequestParam(value = "user_id", required = false) Long user_id) {
        return new CommonResult().success(service.selectPageList(page, page_size, goods_type_id, begin_date, end_date, user_id));
    }
}
